<!DOCTYPE html>
<html lang="zh-cn">

<head>

  <meta content="text/html;charset=utf-8" http-equiv="content-type">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

  <title>滑雪族 - 雪场信息</title>

  <!-- Bootstrap Core CSS -->
<!-- MetisMenu CSS -->
<!-- Custom CSS -->
<!-- Custom Fonts -->
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->  <!--webuploader 引入CSS-->
    <link rel="stylesheet" href="/server/r/bower_components/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/server/r/bower_components/metisMenu/dist/metisMenu.min.css" />
    <link rel="stylesheet" href="/server/r/static/css/sb-admin-2_e507c2b.css" />
    <link rel="stylesheet" type="text/css" href="/server/r/bower_components/font-awesome/css/font-awesome.min.css" />
    <link type="text/css" rel="stylesheet" href="/server/r/static/css/hxz/common_2baa698.css" />
    <link type="text/css" rel="stylesheet" href="/server/r/bower_components/select2/dist/css/select2.min.css" />
    <link rel="stylesheet" type="text/css" href="/server/r/bower_components/alertify/themes/alertify.core.css" />
    <link rel="stylesheet" type="text/css" href="/server/r/bower_components/alertify/themes/alertify.bootstrap.css" />
    <link type="text/css" rel="stylesheet" href="/server/r/vendor/umeditor/themes/default/css/umeditor.css" />
    <link rel="stylesheet" type="text/css" href="/server/r/bower_components/fex-webuploader/dist/webuploader.css" />
</head>

<body>

<div id="wrapper">
  <input type="hidden" id="ski-field-id" value="${(skiField.skiFieldId)!''}">
  <input type="hidden" id="field-provinceId" value="${(skiField.provinceId)!''}">
  <input type="hidden" id="field-cityId" value="${(skiField.cityId)!''}">
  <input type="hidden" id="field-districtId" value="${(skiField.districtId)!''}">
  <!-- Navigation -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">

    <div class="navbar-header">
  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
  <a class="navbar-brand" href="activity-list">滑雪族 管理</a>
</div>
<!-- /.navbar-header -->

<ul class="nav navbar-top-links navbar-right">
  <!-- /.dropdown -->
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
    </a>
    <ul class="dropdown-menu dropdown-user">
      <li><a href="/manage/logout"><i class="fa fa-sign-out fa-fw"></i> 退出系统</a>
      </li>
    </ul>
    <!-- /.dropdown-user -->
  </li>
  <!-- /.dropdown -->
</ul>
<!-- /.navbar-top-links -->

    <div class="navbar-default sidebar" role="navigation">
      <div class="sidebar-nav navbar-collapse">
        <ul class="nav" id="side-menu">
  <li>
    <a href="#"><i class="fa fa-asterisk fa-fw"></i> 产品管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/activity-list"> 产品查询</a>
      </li>
      <li>
        <a href="/manage/manage-organizer-render-activity"> 产品显示控制</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="/#"><i class="fa fa-male fa-fw"></i> 报名管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/player-list"> 报名查询</a>
      </li>
    </ul>
  </li>
  <li>
    <a href="#"><i class="fa fa-list-alt fa-fw"></i> 订单管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/order-list"> 订单查询</a>
      </li>
      <li>
        <a href="/manage/refund-list"> 退款管理</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-check-circle fa-fw"></i> 主办方认证<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/organizer-edit"> 创建主办方</a>
      </li>
      <li>
        <a href="/manage/organizer-list"> 主办方列表</a>
      </li>
      <li>
        <a href="/manage/organizer-print"> 冬令营打印设置</a>
      </li>

    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-picture-o fa-fw"></i> 雪场管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/ski-field-edit"> 创建雪场</a>
      </li>
      <li>
        <a href="/manage/ski-field-list"> 雪场列表</a>
      </li>

    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-users fa-fw"></i> 教练管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/coach-list"> 预约情况</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-credit-card fa-fw"></i> 结算管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/manage-transfer-list"> 转账管理</a>
      </li>
      <li>
        <a href="/manage/manage-withdrawals-apply-list"> 提现申请</a>
      </li>
      <li>
        <a href="/manage/manage-withdrawals-record-list"> 结算列表</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-rmb fa-fw"></i> 财务管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/stream-list"> 交易流水</a>
      </li>
      <li>
        <a href="/manage/manage-bill-record-list"> 对账列表</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-dollar fa-fw"></i> 营销管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/marketing-list"> 返利管理</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-comments fa-fw"></i> 评价管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/comment-list">评价管理</a>
      </li>
    </ul>
  </li>
  <li>
    <a href="#"><i class="fa fa-tasks fa-fw"></i> 定时处理管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/quartz-list"> 定时处理列表</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-wechat fa-fw"></i> 微信页面管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/typography-list"> 微信首页管理</a>
      </li>
      <li>
        <a href="/manage/activity-weight-manage"> 活动置顶</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
</ul>
      </div>
      <!-- /.sidebar-collapse -->
    </div>
    <!-- /.navbar-static-side -->
  </nav>

  <div id="page-wrapper">

    <div class="row">
      <div class="col-lg-12">
        <h3 class="page-header">主办方详情
          <div class="pull-right">
            <div class="form-group">
              <button id="save-btn" class="btn btn-sm btn-success btn-outline">保存</button>
              <a href="/manage/ski-field-list" class="btn btn-sm btn-success btn-outline">返回</a>
            </div>
          </div>
        </h3>
      </div>
      <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
      <div class="col-lg-12">
        <div class="panel panel-default">
          <div class="panel-heading">
            主办方详情
          </div>
          <div class="panel-body">
            <div class="row">
              <div class="col-lg-8">
                <div class="form-group form-require">
                  <label>雪场名称:</label>
                  <input id="ski-field-name" class="form-control" placeholder="请输入雪场名称"
                         value="${(skiField.name)!''}">
                </div>

                <div class="form-group form-require" id="city-select-div">
                  <label class="control-label">地点：</label>

                  <div class="form-inline">
                    <label class="radio-inline">
                      <input id="china-select" name="locationType" type="radio" checked>国内
                    </label>
                    <label class="radio-inline">
                      <input id="nation-select" name="locationType" type="radio">国外
                    </label>
                  </div>
                  <div class="form-inline" id="city-select-area">
                    <select class="form-control input-sm" name="provinceId" id="province_id"></select>
                    <select class="form-control input-sm" name="cityId" id="city_id"></select>
                    <select class="form-control input-sm" name="districtId" id="district_id"></select>
                  </div>

                  <div class="form-inline" style="display: none;" id="nation-select-area">
                    <select class="form-control" id="select-nation"></select>
                  </div>

                </div>

                <div class="form-group form-require">
                  <label class="control-label">详细地址：</label>
                  <input type="text" class="form-control input-sm" name="location" id="ski-field-location" value="${(skiField.location)!''}" placeholder="请输入详细地址" style="width: 340px;">
                </div>

                <div class="form-group form-require">
                  <label>雪场简介:</label>
                  <textarea id="ski-field-introduction" class="form-control" rows="10" style="resize: none;">${(skiField.introduction)!''}</textarea>
                </div>
              </div>
            </div>
            <!-- /.row (nested) -->
          </div>
          <!-- /.panel-body -->
        </div>
        <!-- /.panel -->
      </div>
      <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
  </div>
  <!-- /#page-wrapper -->

</div>
<!-- /#wrapper --><div id="hxz-background" class="background" style="display: none; "></div>
<div id="hxz-progressBar" class="progressBar" style="display: none; ">数据加载中，请稍等...</div>

<script src="/server/r/require.js"></script>
<script type="text/javascript">/*resourcemap*/
require.config({paths:{
  "r/bower_components/jquery/dist/jquery.min": "/server/r/bower_components/jquery/dist/jquery.min",
  "r/bower_components/underscore/underscore-min": "/server/r/bower_components/underscore/underscore-min",
  "r/static/js/hxz/hxz.valid": "/server/r/static/js/hxz/hxz.valid_12cc206",
  "r/static/js/hxz/hxz.rest": "/server/r/static/js/hxz/hxz.rest_07c8105",
  "r/bower_components/alertify/alertify.min": "/server/r/bower_components/alertify/alertify.min",
  "r/static/js/alertify-config": "/server/r/static/js/alertify-config_0cc8db2",
  "r/bower_components/bootstrap/dist/js/bootstrap.min": "/server/r/bower_components/bootstrap/dist/js/bootstrap.min",
  "r/bower_components/metisMenu/dist/metisMenu.min": "/server/r/bower_components/metisMenu/dist/metisMenu.min",
  "r/bower_components/select2/dist/js/select2": "/server/r/bower_components/select2/dist/js/select2",
  "r/static/js/hxz/hxz.ui": "/server/r/static/js/hxz/hxz.ui_0a7714d",
  "r/static/js/hxz/hxz": "/server/r/static/js/hxz/hxz_589b155",
  "r/vendor/umeditor/umeditor.config": "/server/r/vendor/umeditor/umeditor.config",
  "r/vendor/umeditor/umeditor": "/server/r/vendor/umeditor/umeditor",
  "r/bower_components/fex-webuploader/dist/webuploader": "/server/r/bower_components/fex-webuploader/dist/webuploader"
}});

  require(['r/bower_components/jquery/dist/jquery.min','r/static/js/hxz/hxz',"r/vendor/umeditor/umeditor","r/static/js/alertify-config","r/bower_components/fex-webuploader/dist/webuploader","r/bower_components/select2/dist/js/select2"], function ($, hxz, UM, alertify, WebUploader) {

    var ajaxbg = $("#hxz-background,#hxz-progressBar");
    ajaxbg.hide();

    var regionType = "china";
    var nationData = ${nationData};
    var nationHash = {};

    nationData.forEach(function(item) {
      nationHash[item.id] = item.text;
    });

//    console.log(nationHash);

    var $regionChina = $("#china-select");
    var $regionNation = $("#nation-select");

    // 行政区划
    var $province = $('#province_id');
    var $city = $('#city_id');
    var $district = $('#district_id');
    // 详细地址
    var $location = $('#ski-field-location');

    // 行政区划 start
    var getRegionByPrarentId = function (parentId, callback) {
      hxz.doGet({url: hxz.RestApi.regionListByParentId + "?parentId=" + parentId}, function (o) {
        if (o.status == 1) {
          callback(o.data);
        }
      });
    };

    var renderProvince = function () {
      //console.log('****** loading province ******');
      getRegionByPrarentId(1, function (data) {
        //console.log('****** FINISH province ******');
        var html = '<option value="none" selected disabled>请选择省份/直辖市</option>';
        $.each(data, function (index, r) {
          html += '<option value="' + r.regionId + '">' + r.province + '</option>';
        });
        $province.empty().append(html);
      });
    };

    var renderCity = function (provinceId, defaultCityId, defaultDistrictId) {
      //console.log('****** loading city ******');
      getRegionByPrarentId(provinceId, function (data) {
        //console.log('****** FINISH city ******');
        var html = '<option value="none" selected disabled>请选择城市</option>';
        var flag = false;
        $.each(data, function (index, r) {
          // 直辖市处理
          if (r.district) {
            flag = true;
            html = '<option value="' + provinceId + '">' + r.city + '</option>';
            return false;
          }
          html += '<option value="' + r.regionId + '">' + r.city + '</option>';
        });
        $city.empty().append(html);
        if (defaultCityId) {
          $province.val(provinceId);
          $city.val(defaultCityId);
        }

        if (flag) {
          // 如果是直辖市、直接用当前数据查找区
          _renderDistrict(data, provinceId, defaultDistrictId);
        } else if (defaultCityId) {
          // 如果有默认cityId、直接查找区
          renderDistrict(defaultCityId, defaultDistrictId);
        } else {
          $district.empty().append('<option value="none" selected disabled>请先选择县/地区</option>');
        }
      });
    };

    var _renderDistrict = function (data, cityId, defaultDistrictId) {
      var html = '<option value="none" selected disabled>请选择县/地区</option>';
      $.each(data, function (index, r) {
        html += '<option value="' + r.regionId + '">' + r.district + '</option>';
      });
      $district.empty().append(html);
      if (defaultDistrictId) {
        $district.val(defaultDistrictId);
      }
    };

    var renderDistrict = function (cityId, defaultDistrictId) {
      //console.log('****** loading district ******');
      getRegionByPrarentId(cityId, function (data) {
        //console.log('****** FINISH district ******');
        _renderDistrict(data, cityId, defaultDistrictId);
      });
    };

    var bindRegion = function () {
      renderProvince();
      $province.on('change', function (e) {
        var $t = $(e.currentTarget);
        var id = $t.val();
        if (id !== 'none') {
          renderCity(id);
        }
      });
      $city.on('change', function (e) {
        var $t = $(e.currentTarget);
        var id = $t.val();
        if (id !== 'none') {
          renderDistrict(id);
        }
      });
    };
    // 行政区划 end


    function event() {

      $regionChina.click(function () {
        regionType = "china";
        $("#city-select-area").show();
        $("#nation-select-area").hide();
      });

      $regionNation.click(function () {
        regionType = "nation";
        $("#city-select-area").hide();
        $("#nation-select-area").show();
      });

      $("#select-nation").select2({
        language: "zh-CN",
        placeholder: "请选择国家",
        width: "200",
        data: nationData
      });

      bindRegion();

      $("#save-btn").unbind("click").on("click", function () {

        // 各种check
        if (!$('#ski-field-name').val()) {
          alertify.error('雪场名称不能为空');
          return;
        }
        if ($regionNation.is(':checked')) {
          if (!$("#select-nation").val()) {
            alertify.error('地点不能为空');
            return;
          }
        } else {
          if (!$province.val()) {
            alertify.error('省份/直辖市不能为空');
            return;
          } else if (!$city.val()) {
            alertify.error('城市不能为空');
            return;
          } else if (!$district.val()) {
            alertify.error('县/地区不能为空');
            return;
          }
        }

        if (!$location.val()) {
          alertify.error('详细地址不能为空');
          return;
        }
        if (!$('#ski-field-introduction').val()) {
          alertify.error('雪场简介不能为空');
          return;
        }

        var address = '';

        if ($regionNation.is(':checked')) {
          address = nationHash[$("#select-nation").val()] + ' ' + $location.val();
        } else {
          address = $('#province_id option:selected').text() + ' ' + $('#city_id option:selected').text() + ' ' + $('#district_id option:selected').text() + ' ' + $location.val();
        }

        var data = {
          name: $('#ski-field-name').val(),
          provinceId: ($regionNation.is(':checked')) ? $("#select-nation").val() : $province.val(),
          cityId: ($regionNation.is(':checked')) ? $("#select-nation").val() : $city.val(),
          districtId: ($regionNation.is(':checked')) ? $("#select-nation").val() : $district.val(),
          location: $location.val(),
          introduction: $('#ski-field-introduction').val(),
          address: address
        };

//        console.log(data);

        var skiFieldId = $("#ski-field-id").val();
        if (skiFieldId && skiFieldId.length > 0) {

          data.skiFieldId = skiFieldId;
          hxz.doPost({url: hxz.RestApi.manageSkiFieldUpdate, data: data}, function (data) {

            if (data.status == "0") {
              return alertify.error(data.msg, "danger");
            }

            if (data.status == "1") {
              alertify.log("修改雪场成功!");
              setTimeout(function () {
                window.location.href = "/manage/ski-field-list";
              }, 1000);
            }
          });
        } else {

          hxz.doPost({url: hxz.RestApi.manageSkiFieldAdd, data: data}, function (data) {
            if (data.status == "0") {
              return alertify.error(data.msg, "danger");
            }

            if (data.status == "1") {
              alertify.log("添加雪场成功!");
              setTimeout(function () {
                window.location.href = "/manage/ski-field-list";
              }, 1000);

            }
          });
        }
      });
    }

    event();
    // 编辑
    if ($('#ski-field-id').val() != '') {
      var provinceId = $("#field-provinceId").val();
      var cityId = $("#field-cityId").val();
      var districtId = $("#field-districtId").val();
      if (provinceId == cityId && cityId == districtId) {
        $("#nation-select").trigger("click");
        $("#select-nation").val(cityId).trigger("change");
      } else {
        // 设定行政区划值
        renderCity(provinceId, cityId, districtId);
      }
    }
  });
</script>
</body>
</html>
